<%@ page import="admin.Connectmysql" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2025/6/19
  Time: 23:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    response.setCharacterEncoding("UTF-8");
    String examName = request.getParameter("exam_name");
    String text = request.getParameter("question_text");
    String option_a = request.getParameter("option_a");
    String option_b = request.getParameter("option_b");
    String option_c = request.getParameter("option_c");
    String option_d = request.getParameter("option_d");
    String correct_answer = request.getParameter("correct_answer");
    String score = request.getParameter("score");
    Connectmysql cmysql = new Connectmysql(
            "jdbc:mysql://localhost:3306/exam1",
            "root",
            "root",
            "com.mysql.cj.jdbc.Driver");
    try {
        if(cmysql.open()){
                ResultSet number = cmysql.executeSql("SELECT max(id) FROM question WHERE exam = ?",new Object[]{examName});
                int id=1;
                if(number!=null&&number.next()){
                    id=number.getInt(1)+1;
                }
                System.out.println("exam"+examName);
                int rst2 = cmysql.executeSqlUpdate("INSERT INTO question (id,exam,text, A, B, C,D,answer,score) VALUES (?, ?,?, ?, ?, ?,?,?,?);"
                        ,new Object[]{id ,examName,text,option_a,option_b,option_c,option_d,correct_answer,score}
                );
                if(rst2>0){
                    //添加成功
                    System.out.println("添加成功");
                }else {
                    //添加失败
                }
            }
    } catch (ClassNotFoundException f) {
        f.printStackTrace();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
    }




%>
</body>
</html>
